package cn.lixiaodan.hqlbuilder.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class AppPrefs extends Properties {
	public static AppPrefs prefs = null;

	public synchronized static AppPrefs getApplicationPrefs() {
		if (prefs == null) {
			prefs = new AppPrefs();
			InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("system.properties");
			try {
				prefs.load(is);
			} catch (IOException e) {
			}
		}
		return prefs;
	}

	public static String value(String key) {
		return getApplicationPrefs().getProperty(key);
	}

	public static String value(String key, String defaultvalue) {
		String value = value(key);
		if (value == null || value.length() == 0) {
			value = defaultvalue;
		}
		return value;
	}

	public static String getString(String key) {
		return getApplicationPrefs().getProperty(key);
	}

	public static Boolean getBoolean(String key) {
		return Boolean.parseBoolean(getString(key));
	}

}
